package com.gwnet.cabinet.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gwnet.cabinet.domian.CabinetBox;
import com.gwnet.cabinet.domian.CabinetBoxLog;
import com.gwnet.cabinet.domian.base.Result;
import com.gwnet.cabinet.domian.bo.*;
import com.gwnet.cabinet.service.CabinetBoxService;
import com.gwnet.common.core.domain.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 外卖柜-箱格表 前端控制器
 * </p>
 *
 * @author WangLiang
 * @since 2024-07-23
 */
@Slf4j
@RestController
@RequestMapping("/cabinetBox")
public class CabinetBoxController {


    private final CabinetBoxService cabinetBoxService;

    @Autowired
    public CabinetBoxController(CabinetBoxService cabinetBoxService) {
        this.cabinetBoxService = cabinetBoxService;
    }


    /**
     * 往外卖柜放外卖
     * @param cabinetBoxOpenBO
     * @return
     */
    @PostMapping("/putToBox")
    public ResponseResult<Boolean> putToBox(@RequestBody CabinetBoxOpenBO cabinetBoxOpenBO){
        Boolean status = cabinetBoxService.putToBox(cabinetBoxOpenBO);
        return ResponseResult.success(status);
    }

    /**
     * 从外卖柜取外卖
     * @param cabinetTakeBoxBO
     * @return
     */
    @PostMapping("/getToBox")
    public ResponseResult<Boolean> getToBox(@RequestBody CabinetTakeBoxBO cabinetTakeBoxBO){
        Boolean status = cabinetBoxService.getToBox(cabinetTakeBoxBO);
        return ResponseResult.success(status);
    }

    /**
     * 管理员开箱
     * @param adminOpenBO
     * @return
     */
    @PostMapping("/adminOpen")
    public ResponseResult<Boolean> adminOpen(@RequestBody AdminOpenBO adminOpenBO){
        Boolean flag = cabinetBoxService.adminOpen(adminOpenBO);
        return ResponseResult.success(flag);
    }


    /**
     * 超时外卖
     * @param timeOutBoxBO
     * @return
     */
    @PostMapping("/getTimeOutList")
    public ResponseResult<List<CabinetBoxLog>> getTimeOutList(@RequestBody TimeOutBoxBO timeOutBoxBO){
        List<CabinetBoxLog> timeOutList = cabinetBoxService.getTimeOutList(timeOutBoxBO);
        return ResponseResult.success(timeOutList);
    }


    /**
     * 第三方系统回调函数
     * @param takeEventBO
     * @return
     */
    @PostMapping("/takeEvent")
    public ResponseResult takeEvent(@RequestBody TakeEventBO takeEventBO){
        Boolean flag = cabinetBoxService.takeEvent(takeEventBO);
        return ResponseResult.success(flag);
    }

    /**
     * 分页查询列表
     * @param boxPageBO
     * @return
     */
    @PostMapping("/page")
    public ResponseResult<IPage<CabinetBox>> page(@RequestBody CabinetBoxPageBO boxPageBO){
        IPage<CabinetBox> page = cabinetBoxService.page(boxPageBO);
        return ResponseResult.success(page);
    }


    /**
     * 根据设备ID获取外卖柜下的格子列表
     * @param boxListBO
     * @return
     */
    @PostMapping("/listByDevSn")
    public ResponseResult<List<CabinetBox>> listByDevSn(@RequestBody CabinetBoxListBO boxListBO){
        List<CabinetBox> boxList = cabinetBoxService.listByDevSn(boxListBO);
        return ResponseResult.success(boxList);
    }


    /**
     * 修改状态
     * @param boxUpdateBO
     * @return
     */
    @PostMapping("/updateState")
    public ResponseResult<Boolean> updateState(@RequestBody CabinetBoxUpdateBO boxUpdateBO){
        Boolean flag = cabinetBoxService.updateState(boxUpdateBO);
        return ResponseResult.success(flag);
    }

    /**
     * 根据箱格ID查询箱格详情
     * @param boxViewBO
     * @return
     */
    @PostMapping("/view")
    public ResponseResult<CabinetBox> view(@RequestBody CabinetBoxViewBO boxViewBO){
        CabinetBox cabinetBox = cabinetBoxService.view(boxViewBO.getBoxId());
        return ResponseResult.success(cabinetBox);
    }



//    @GetMapping("/takeEventTest")
//    public ResponseResult test(){
//        log.info("打印进入到Test");
//        return ResponseResult.success();
//    }


}

